package com.supor.aiot.mine.ui.wish;

import android.annotation.SuppressLint;
import android.app.Application;

import com.android.baseconfig.common.utils.Logc;
import com.supor.aiot.common.base.BaseViewModel;
import com.supor.aiot.common.entity.Result;
import com.supor.aiot.mine.api.WishImpl;
import com.supor.aiot.mine.bean.WishBean;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

public class AddWishViewModel extends BaseViewModel {
    int index = 0;
    MutableLiveData<Result> resultData = new MutableLiveData<>();

    public AddWishViewModel(@NonNull Application application) {
        super(application);
    }

    public MutableLiveData<Result> getOperationResult() {
        return resultData;
    }

    @SuppressLint("CheckResult")
    public void addWish(WishBean wishBean) {
        WishImpl.getInstance().addWish(wishBean).subscribe(result -> {
            if (result.isSuccess()) {
                resultData.setValue(new Result.Success(result.data));
            } else {
                resultData.setValue(new Result.Error("addWish failed"));
                Logc.e("accept: failed");
            }
        }, throwable -> {
            throwable.printStackTrace();
            resultData.setValue(new Result.Error(new Exception(throwable)));
            Logc.e("accept: failed: " + throwable.getMessage());
        });
    }

}
